<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.*,util.*,dal.*,model.*,bll.*"%>
<%
	PersonModel obj;
	Object temp = request.getAttribute("person");
	if (temp != null) {
		try {
			obj = (PersonModel) temp;
		} catch (Exception ex) {
			obj = new PersonModel();
		}
	} else {
		obj = new PersonModel();
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Person</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(pageLoaded);

function pageLoaded()
{
	turnOnNumbericInput();
	initTooltip();	
	initDatePicker();
} 
var requiredInputs = [['first_name','first_name_required']];
var intInputs = [];
var doubleInputs = [];
var dateInputs = [['birthdate_date', 'birthdate_date_invalid']];
var timeInputs = [];
var mailInputs = [['company_email','company_email_invalid'],['personal_email','personal_email_invalid']];
	

function checkInputs() {
	var valid = true;

	if (checkRequiredInputs(requiredInputs) == false) {
		valid = false;
	}
	if (checkIntInputs(intInputs) == false) {
		valid = false;
	}
	if (checkDoubleInputs(doubleInputs) == false) {
		valid = false;
	}
	if (checkDateInputsForCorrectedFormatOnly(dateInputs, dateFormat) == false) {
		valid = false;
	}	
	if (checkTimeInputs(timeInputs) == false) {
		valid = false;
	}
	if (checkMailInputs(mailInputs) == false) {
		valid = false;
	}

	// SPECIFIC VALIDATE CODE HERE		

	return valid;
}
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
				<form id="inputForm" action="person?mode=update" method="post" onSubmit="return checkInputs()" >
					<table class="tblInput">
						<tr>
							<td class="inputHeader">EDIT PERSON INFO</td>
						</tr>
							<tr>
					<td style="padding-left: 200px; padding-right: 200px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput">
								<input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getId()%>" title="Id of this person. Note: Can not edit"/>
								<span class="textGuide"> (Can not edit)</span>
							</td>
							<td class="tdErrMsg"></td>
							<td rowspan="8"></td>
							<td class="tdFieldName">Mobile</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="mobile" name="mobile" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getMobileToString() %>" title="Mobile number of person. Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Employee</td>
						<td class="tdFieldInput">
							<select id="id_employee" name="id_employee" class="hyjack" title="Choose an employee who this person is.">
								<%=HtmlUtil.<EmployeeModel>genModelSelect(CacheUtil.getEmployeeList(), null,obj.getIdEmployee(), false, true)%>
							</select>
							<input class="btnAdd" type="button" id="addNewEmployee" value="" onclick="ajaxAddItem('#id_employee', 'employee', 'name', 'Please enter new employee name!');" title="Click here to add new employee."/>
						</td>
						<td class="tdErrMsg">
						</td>
							<td class="tdFieldName">Company phone</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="company_phone" name="company_phone" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getCompanyPhoneToString() %>" title="Company phone number of  person. Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">First Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="first_name" name="first_name" maxlength="25" value="<%=obj.getFirstNameToString() %>" title="First name of person. Note: Required." onblur="validateRequiredInput('first_name');"/>
							</td>
							<td class="tdErrMsg">
								<span id="first_name_required" class="errMsg" style="display: none;" title="First name is required">(!)</span> 
								
							</td>
							<td class="tdFieldName">Home phone</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="home_phone" name="home_phone" maxlength="13" onkeydown="phoneNumberTextKeyDown(event, this);" onkeyup="phoneNumberTextKeyUp(this);" value="<%=obj.getHomePhoneToString() %>" title="Home phone number of  person. Format: (+)xxxxx..." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Middle Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="middle_name" name="middle_name" maxlength="25" value="<%=obj.getMiddleNameToString() %>" title="Middle name of person." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Company Email</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="company_email" name="company_email" maxlength="255" value="<%=obj.getCompanyEmailToString() %>" title="Company email of person." onchange="validateMailInput('company_email')" />
							</td>
							<td class="tdErrMsg">
								<span id="company_email_invalid" class="errMsg" style="display: none;" title="The email you input is invalid">(!)</span> 
							</td>
							
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Last Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="last_name" name="last_name" maxlength="25" value="<%=obj.getLastNameToString() %>" title="Last name of person." />
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Personal Email</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="personal_email" name="personal_email" maxlength="255" value="<%=obj.getPersonalEmailToString() %>" title="Personal email of person." onchange="validateMailInput('personal_email')" />
							</td>
							<td class="tdErrMsg">
								<span id="personal_email_invalid" class="errMsg" style="display: none;" title="The email you input is invalid">(!)</span> 
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Address</td>
							<td class="tdFieldInput">
								<textarea id="address" name="address" rows="5" class="inputTextarea" title="Address of person."><%=obj.getAddressToString() %></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
							<td class="tdFieldName">Identity No</td>							
							<td class="tdFieldInput">
								<input class="inputInt" type="text" id="identity_no" name="identity_no" maxlength="10" value="<%=obj.getIdentityNoToString() %>"
									title="Identity No of person. Note: only integer allowed" /> 
							</td>
							<td class="tdErrMsg">
								
							</td>	
						</tr>
						<tr>
							<td class="tdFieldName">Birthdate</td>				
							<td class="tdFieldInput">
								<input type="text" maxlength="10" class="inputDate" id="birthdate_date" name="birthdate_date" value="<%=obj.getBirthdateToString() %>" title="Click to choose birthdate." onchange="validateDateInput('birthdate_date',false)" />
								<span class="textGuide"> (dd/mm/yyyy)</span>								
							</td>
							<td class="tdErrMsg">
								
								<span id="birthdate_date_invalid" class="errMsg" style="display: none;" title="You've entered an invalid date.<br/>The format is <b>dd/mm/yyyy at hh:mm</b>">(!)</span>
							</td>
							<td class="tdFieldName">Gender</td>
							<td class="tdFieldInput">
								<select id="gender" name="gender" class="hyjack" title="Choose gender for person.">
								<%=HtmlUtil.genEnumSelect(EnumName.Gender, null,obj.getGender()==true?1:2) %>
							</select>					
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput">
								<textarea id="description" name="description" rows="5" class="inputTextarea" title="Description for person."><%=obj.getDescriptionToString() %></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
							<td colspan="4"></td>
						</tr>

						<tr class="trInputBottom">
							<td colspan="8" class="tdSubmit" style="text-align: center;"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td>

						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<%
	
		String urlPersonList = "personList.jsp?embedded=true";
	%>
		<jsp:include page='<%=urlPersonList%>'></jsp:include>
	</div>
</body>
</html>